<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "user_secondary_auth_group_access".
 *
 * @property int $id
 * @property int $user_id 鐢ㄦ埛id
 * @property int $user_secondary_id 娆＄骇鐢ㄦ埛id
 * @property int $user_secondary_auth_group_id 娆＄骇鐢ㄦ埛鏉冮檺缁刬d
 *
 * @property User $user
 * @property UserSecondary $userSecondary
 * @property UserSecondaryAuthGroup $userSecondaryAuthGroup
 */
class UserSecondaryAuthGroupAccess extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_secondary_auth_group_access';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'user_secondary_id', 'user_secondary_auth_group_id'], 'required'],
            [['user_id', 'user_secondary_id', 'user_secondary_auth_group_id'], 'integer'],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
            [['user_secondary_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserSecondary::className(), 'targetAttribute' => ['user_secondary_id' => 'id']],
            [['user_secondary_auth_group_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserSecondaryAuthGroup::className(), 'targetAttribute' => ['user_secondary_auth_group_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '用户id',
            'user_secondary_id' => '次级用户id',
            'user_secondary_auth_group_id' => '次级用户权限组id',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserSecondary()
    {
        return $this->hasOne(UserSecondary::className(), ['id' => 'user_secondary_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserSecondaryAuthGroup()
    {
        return $this->hasOne(UserSecondaryAuthGroup::className(), ['id' => 'user_secondary_auth_group_id']);
    }
}
